package com.foreveross.bsl.common.utils.balance;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/** 抽象zk简单数据结构
 *  
 * @author hyw
 *
 */
public class ZkNode implements Serializable {
	
	private static final long serialVersionUID = 8377738349539819491L;
	
	private ZkNode zParent;
	private Set<ZkNode> zChilds = Collections.synchronizedSet(new HashSet<ZkNode>());
	private String name;
	private String data;
	private String path; // 当前节点path 
	private boolean isLast; // 是否最后一级
	
	public ZkNode getzParent() {
		return zParent;
	}
	public void setzParent(ZkNode zParent) {
		this.zParent = zParent;
	}
	
	public void addzChilds(ZkNode child) {
		this.zChilds.add(child);
	}
	
	public Set<ZkNode> getzChilds() {
		return zChilds;
	}
	public void setzChilds(Set<ZkNode> zChilds) {
		this.zChilds = zChilds;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getData() {
		return data;
	}
	public void setData(String data) {
		this.data = data;
	}
	public boolean isLast() {
		return isLast;
	}
	public void setLast(boolean isLast) {
		this.isLast = isLast;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((data == null) ? 0 : data.hashCode());
		result = prime * result + (isLast ? 1231 : 1237);
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ZkNode other = (ZkNode) obj;
		if (data == null) {
			if (other.data != null)
				return false;
		} else if (!data.equals(other.data))
			return false;
		if (isLast != other.isLast)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		return true;
	}
	
	
}